// pages/login/login.js
const App = getApp();
var api = require("../../utils/api");
import request from "../../utils/request";
const {
  $Message
} = require('../commpoents/iview-dist/base/index.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jobNumber:"",
    lastSixForIdCard:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navH: App.globalData.navHeight
    })
  },
  changeJobNumber(e) {
    this.setData({
      jobNumber: e.detail.value
    })
  },
  changeLastSixForIdCard(e) {
    this.setData({
      lastSixForIdCard: e.detail.value
    })
  },
  start: function () {
    var url = api.LoginApi
    var params = {
      "access_token": "5b7f60aca7e7f6f8c680b1b219ad3ec6",
      "jobNumber": this.data.jobNumber,
      "lastSixForIdCard": this.data.lastSixForIdCard
    }
    request(url, params, "POST").then(res => {
      if (res.code === 0) {
        if (res.data.isCompanyEmployee){
          $Message({
            content: res.msg,
            type: 'success'
          });
          wx.setStorageSync("userData", res.data.employee)
          setTimeout(() => {
            wx.redirectTo({
              url: '/pages/monthlyCalendar/monthlyCalendar',
            })
          }, 1000);
        }else{
          $Message({
            content: "不是内部员工，请联系管理员",
            type: 'warning'
          });
        }
      }else{
        $Message({
          content: res.msg,
          type: 'warning'
        });
      }
    })
    // wx.redirectTo({
    //   url: '/pages/monthlyCalendar/monthlyCalendar',
    // })
  }
})